﻿namespace SRF.UI.Html
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using System.Globalization;
    using System.Linq.Expressions;
    using System.Text;
    using System.Web.Routing;
    using System.Web.Mvc;
    using System.Linq;

    /// <summary>
    /// 
    /// </summary>
    public enum CheckedValue
    {
        Default
    }
    /// <summary>
    /// 
    /// </summary>
    public static class InputExtensions
    {
        public static MvcHtmlString CheckBox(this HtmlHelper htmlHelper, string name, CheckedValue checkedValue)
        {
            bool isChecked = (htmlHelper.ViewData[name] != null && (htmlHelper.ViewData[name].ToString() == "true,false" || htmlHelper.ViewData[name].ToString() == "true"));

            return System.Web.Mvc.Html.InputExtensions.CheckBox(htmlHelper, name, isChecked);
        }
        public static MvcHtmlString CheckBox(this HtmlHelper htmlHelper, string name, CheckedValue checkedValue, IDictionary<string, object> htmlAttributes)
        {
            bool isChecked = (htmlHelper.ViewData[name] != null && (htmlHelper.ViewData[name].ToString() == "true,false" || htmlHelper.ViewData[name].ToString() == "true"));

            return System.Web.Mvc.Html.InputExtensions.CheckBox(htmlHelper, name, isChecked, htmlAttributes);
        }

        public static ModelMetadata GetModelMetadata(Type t, string propertyName)
        {
            ModelMetadataProvider provider = ModelMetadataProviders.Current;
            ModelMetadata containerMetadata = new ModelMetadata(provider, null, () => null, t, null);
            return containerMetadata.Properties.FirstOrDefault(m => m.PropertyName == propertyName);
        }
    }
}